package com.ftg.learn;

import com.alibaba.dashscope.aigc.completion.ChatCompletion;
import com.alibaba.dashscope.aigc.completion.ChatCompletionParam;
import com.alibaba.dashscope.aigc.completion.ChatCompletions;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * @author 布衣
 */
public class LearnAi {

    public static void main(String[] args) throws NoApiKeyException, InputRequiredException {
        Constants.apiKey="sk-510b917932744b3680b858b474fbd919";
        Constants.baseHttpApiUrl="https://dashscope.aliyuncs.com/compatible-mode/v1";

        ChatCompletions c = new ChatCompletions();

        System.out.println("欢迎使用...AI智能体");
        System.out.println("请输入您的问题");
        Scanner s = new Scanner(System.in);

        List<Message> list = new ArrayList<>();

        //system(系统) user(用户) assistant(提示)
        Message SysMess = Message.builder()
                .role(Role.SYSTEM.getValue())
                .content("你是齐齐哈尔大学计控院的专业教授")
                .build();
        list.add(SysMess);

        Message mess = Message.builder()
                .role(Role.USER.getValue())
                .content(s.next())
                .build();
        list.add(mess);
        //参数
        ChatCompletionParam param = ChatCompletionParam.builder()
                //llm []
                .model("qwen-plus")
                .messages(list)
                .build();

        ChatCompletion call = c.call(param);

        List<ChatCompletion.Choice> choices = call.getChoices();

        System.out.println("AI:"+choices.get(0).getMessage().getContent());

        Message assMess = Message.builder()
                .role(Role.ASSISTANT.getValue())
                .content(choices.get(0).getMessage().getContent())
                .build();
        list.add(mess);

        System.out.println("请输入您的问题");
        Message user1 = Message.builder()
                .role(Role.USER.getValue())
                .content(s.next())
                .build();
        list.add(user1);


        //参数
        ChatCompletionParam param1 = ChatCompletionParam.builder()
                //llm []
                .model("qwen-plus")
                .messages(list)
                .build();

        ChatCompletion call1 = c.call(param1);
        System.out.println(call1.getChoices().get(0).getMessage().getContent());
    }

}
